<?php
if(is_user_logged_in()){
	$user_id = get_buzzr_users_pod_id();
	$users = new Pod('users',$user_id);
	$users->page = 1;
	$users->search = false;
	$user_id = $users->get_field('id');
  	$user_slug = $users->get_field('slug');
  	$user_pod_name = $users->get_field('name');
  	$user_pod_email = $users->get_field('wp_user.user_email');
}
$buzzr_cities = get_buzzr_cities();
$url = BUZZR_URL.'/api2/?t=localoffers-mumbai&items=10&format=json&apikey=4d6baa6912b42';

$curl_json_output = buzzr_download_page($url);
$json_decoded = json_decode($curl_json_output, true);
?>

<div id="get_widget" class="get_widget">
<div class="center_align"><h1>Get a Customized Buzzr Widget</h1></div>

<!-- Form -->
<div id="form">
<label for="users_name">Your Name <span class="asteric">*</span></label><input <?php if(!empty($user_pod_name)){ echo 'value = "'.$user_pod_name.'"'; } ?> type="text" name="users_name" id="users_name" />
<input type="hidden" id="user_id" name="user_id" value="<?php echo $user_id; ?>" />
<input type="hidden" id="user_slug" name="user_slug" value="<?php echo $user_slug; ?>" />
<label for="email">Your Email Id <span class="asteric">*</span></label><input <?php if(!empty($user_pod_email)){ echo 'value = "'.$user_pod_email.'"'; } ?> type="text" name="email" id="email" />
<label for="website">Website <span class="asteric">*</span></label><input type="text" name="website" id="website" />
<label for="widget_colour">Widget Colour <span class="asteric">*</span></label><input type="text" name="widget_colour" id="widget_colour" />
<label for="width">Width <span class="asteric">*</span></label><input value="250" type="text" name="width" id="width" />
<label for="type">Type of Offer <span class="asteric">*</span></label><input id="type" type="radio" name="type" value="localoffers" checked><span style="float: left;">Local Offers</span><input id="type" type="radio" name="type" value="dailydeals"><span style="float: left;">Daily Deals</span>

<label for="city">Deal City <span class="asteric">*</span></label>

<select id="city" name="city">
<?php  
    foreach($buzzr_cities as $city_val){ ?>
    	<?php if($city_val['name'] == 'Mumbai'){ ?>
    		<option value="<?php echo sanitize_title($city_val['name']); ?>" selected="selected"><?php echo $city_val['name']; ?></option>
  		<?php }else{ ?>
    		<option value="<?php echo sanitize_title($city_val['name']); ?>"><?php echo $city_val['name']; ?></option>
  		<?php } 
    } 
?>
</select> 

<?php if(!empty($user_id)){ ?>
<label></label><input type="button" name="submit" id="submit" value="Get Code!" /><span class="fltLeft loading"><img src="<?php echo BUZZR_WP_URL.'/wp-content/pfiles/images/loader.gif'; ?>" /></span>

<?php
}else{
  echo '<label></label><span class="nlogin_widget"><a rel="nofollow" href="/wp-login.php" class="simplemodal-login" title="Login to Get Widget Code">Login to Get Widget Code!</a></span>';
}
?>
<div style="clear: both; float: right; font-size: 12px; margin-right: 70px;"><a href="http://buzzr.in/contact-us/" target="_blank">Contact us</a> for help with implementation</div>
</div>
<!-- Form -->

<!-- Widget Preview -->
  <div id="contentDiv">
    <div id="widget_logo"><a target="_blank" href="<?php echo BUZZR_URL; ?>?utm_source=widget+preview&utm_medium=web&utm_campaign=Widget+Preview&ref=<?php echo $user_slug; ?>"><img src="<?php echo BUZZR_WP_URL.'/wp-content/pfiles/images/buzzr_widget1.png'; ?>" /></a><font size="3" color="white">{City} Offers</font></div>
      <div id="allDealsDiv">    
        <?php
        foreach($json_decoded as $key=>$value)
        {
          $red_link = $value['offer_red_link'];
		  if(empty($red_link)){
			$red_link = $value['offer_link'];
		  }
		  echo '<div id="item_'.$key.'" class="item"><a target="_blank" href="'.$red_link.'&ref='.$user_slug.'">'.stripslashes($value['offer_name']).'</a></div>';
        }
        ?>
      </div>
      <div id="footer_note">Powered by <a target="_blank" href="<?php echo BUZZR_URL; ?>?utm_source=widget+preview&utm_medium=web&utm_campaign=Widget+Preview&ref=<?php echo $user_slug; ?>">Buzzr.in</a></div>
  </div>
<!-- Widget Preview -->
<div class="fltLeft result1"></div>
</div>